<?php
class Register extends Zend_Form
{
    public function init()
    {
    	$this->setAction("/user/register");
    	$this->setMethod("post");

        $username = new Zend_Form_Element_Text('new_username', array('id'=>'new_username'));
		$username->setLabel('Имя пользователя')
			->addFilter('StringTrim')
			->addValidator('Alpha')
			->addValidator('StringLength', false, array(3, 20))
			->setRequired(true);

		$password = new Zend_Form_Element_Text('new_password', array('id' => 'new_password'));
		$password->setLabel('Пароль')
			->addFilter('StringTrim')
			->addValidator('Alnum')
			->addValidator('StringLength', false, array(6,20))
			->setRequired(true);
			
        $password2 = new Zend_Form_Element_Text('new_password2', array('id' => 'new_password2'));
		$password2->setLabel('Повторите пароль')
			->addFilter('StringTrim')
			->addValidator('Alnum')
			->addValidator('StringLength', false, array(6,20))
			->addValidator('Identical', false, array('token'=>'new_password'))
			->setRequired(true);
		
		$lastname = new Zend_Form_Element_Text('lastname', array('id'=>'lastname'));
		$lastname->setLabel('Фамилия')
			->addFilter('StringTrim')
			->addValidator('Alpha')
			->addValidator('StringLength', false, array(3, 20))
			->setRequired(true);
			
		$firstname = new Zend_Form_Element_Text('firstname', array('id'=>'firstname'));
		$firstname->setLabel('Имя')
			->addFilter('StringTrim')
			->addValidator('Alpha')
			->addValidator('StringLength', false, array(3, 20))
			->setRequired(true);

		$middlename = new Zend_Form_Element_Text('middlename', array('id'=>'middlename'));
		$middlename->setLabel('Отчество')
			->addFilter('StringTrim')
			->addValidator('Alpha')
			->addValidator('StringLength', false, array(3, 20))
			->setRequired(true);

		$email = new Zend_Form_Element_Text('email', array('id'=>'email'));
		$email->setLabel('E-mail')
			->addFilter('StringTrim')
			->addValidator('EmailAddress')
			->setRequired(true);
			
       	$phone = new Zend_Form_Element_Text('phone', array('id' => 'phone'));
		$phone->setLabel('Телефон:')
			->addFilter('StripTags')
			->addFilter('StringTrim')
			->addValidator('Regex', null, array(
								'pattern'=> '/^\+?\d{11}$/',
								'messages' => array(
									Zend_Validate_Regex::NOT_MATCH =>
										"'%value%' неверный формат номера телефона.<br/>Требуется указать номер в формате: +88888888888"
									)
								)
							)
			->setRequired(true);
/*
		$registerAs = new Zend_Form_Element_Radio('register_as', array('id' => 'register_as'));
		$registerAs->setLabel('Тип регистрации')
			->addFilter('StripTags')
			->addFilter('StringTrim')
			->setRequired(true);
		$registerAs->addMultiOption(0, 'Пользователь');
		$registerAs->addMultiOption(1, 'Тур-агентство');
*/			
		$sbmt = new Zend_Form_Element_Submit('place');
		$sbmt->setLabel('Зарегистрироваться');
		
        $this->addElements(array(/*$registerAs, */$username, $password, $password2, $lastname, $firstname, $middlename, $email, $phone, $sbmt));

    	foreach ( $this->getElements() as $element ) {
        	$element->setDecorators(
        		array(
		        	'ViewHelper',
        			'Errors',
		        	array(array('data' => 'HtmlTag'), array('tag' => 'div', 'id' => $element->getId().'-data')),
		        	array(array('label' => 'Label'), array('tag' => 'div', 'escape' => false)),
		        	array(array('row' => 'HtmlTag'), array('tag' => 'div', 'id' => $element->getId().'-element', 'class' => $element->class )),
	        	)
        	);
        }
		$sbmt->setDecorators(array('ViewHelper', array('data'=>'HtmlTag', 'tag'=>'div')));

        $this->setDecorators(array(
            'FormElements',
            array('HtmlTag', array('tag' => 'div', 'id' => 'register-form')),
            array('Description', array('placement' => 'prepend')),
            'Form'
        ));
    }
}